package com.ruoyi.system.controller;

import java.util.List;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import com.ruoyi.system.domain.SysUserDetail;
import com.ruoyi.system.service.ISysUserDetailService;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.page.TableDataInfo;

/**
 * 用户前台信息表Controller
 * 
 * @author hyb
 * @date 2023-02-05
 */
@RestController
@RequestMapping("/userDetail")
public class SysUserDetailController extends BaseController
{
    @Autowired
    private ISysUserDetailService sysUserDetailService;

    @GetMapping("/listTribeNumber")
    public AjaxResult listTribeNumber(@RequestParam("tribeNumber")String tribeNumber){
        List<SysUserDetail> sysUserDetails = sysUserDetailService.selectUserDetailList(tribeNumber);
        return AjaxResult.success().put("list",sysUserDetails);
    }

    /**
     * 查询用户前台信息表列表
     */
    @RequiresPermissions("system:userDetail:list")
    @GetMapping("/list")
    public TableDataInfo list(SysUserDetail sysUserDetail)
    {
        startPage();
        List<SysUserDetail> list = sysUserDetailService.selectSysUserDetailList(sysUserDetail);
        return getDataTable(list);
    }

    /**
     * 导出用户前台信息表列表
     */
    @RequiresPermissions("system:userDetail:export")
    @Log(title = "用户前台信息表", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, SysUserDetail sysUserDetail)
    {
        List<SysUserDetail> list = sysUserDetailService.selectSysUserDetailList(sysUserDetail);
        ExcelUtil<SysUserDetail> util = new ExcelUtil<SysUserDetail>(SysUserDetail.class);
        util.exportExcel(response, list, "用户前台信息表数据");
    }

    /**
     * 获取用户前台信息表详细信息
     */
    @RequiresPermissions("system:userDetail:query")
    @GetMapping(value = "/{integral}")
    public AjaxResult getInfo(@PathVariable("integral") Long integral)
    {
        return success(sysUserDetailService.selectSysUserDetailByIntegral(integral));
    }

    /**
     * 新增用户前台信息表
     */
    @RequiresPermissions("system:userDetail:add")
    @Log(title = "用户前台信息表", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SysUserDetail sysUserDetail)
    {
        return toAjax(sysUserDetailService.insertSysUserDetail(sysUserDetail));
    }

    /**
     * 修改用户前台信息表
     */
    @RequiresPermissions("system:userDetail:edit")
    @Log(title = "用户前台信息表", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SysUserDetail sysUserDetail)
    {
        return toAjax(sysUserDetailService.updateSysUserDetail(sysUserDetail));
    }

    /**
     * 删除用户前台信息表
     */
    @RequiresPermissions("system:userDetail:remove")
    @Log(title = "用户前台信息表", businessType = BusinessType.DELETE)
	@DeleteMapping("/{integrals}")
    public AjaxResult remove(@PathVariable Long[] integrals)
    {
        return toAjax(sysUserDetailService.deleteSysUserDetailByIntegrals(integrals));
    }
}
